/**
 * @author LKQ
 * @date 2022/1/4 16:08
 * @description 动态规划（滚动数组）
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.tribonacci(25));
    }

    public int tribonacci(int n) {
        if (n < 2) {
            return n;
        }
        if (n == 2) {
            return 1;
        }
        int p = 0, q = 1, r = 1, k = 0;
        for (int i = 3; i <= n; i++) {
            k = p + q + r;
            p = q;
            q = r;
            r = k;
        }
        return k;
    }
}
